export function getQuery() {
	const pages = getCurrentPages();
	const curPage = pages[pages.length - 1];
	if (curPage && curPage.options) {
		return curPage.options
	} else {
		return {}
	}
}

export function getQueryParams(name) {
	//获取页面栈
	const pages = getCurrentPages();
	//获取路由参数
	const curPage = pages[pages.length - 1];
	return name ? curPage.options[name] : curPage.options;
}


// 解析整个 URL 字符串中的所有参数并返回一个对象
export function getUrlParams(url) {
	let decodedUrl = decodeURIComponent(url);
	let queryString = decodedUrl.split('?')[1] || '';
	let paramsObj = {};

	if (queryString) {
		queryString.split('&').forEach(param => {
			let [key, value] = param.split('=');
			paramsObj[key] = value ? decodeURIComponent(value) : '';
		});
	}
	return paramsObj;
}

// 根据参数名称获取特定参数的值
export function getQueryString(url, name) {
	let paramsObj = getUrlParams(url);
	return paramsObj[name] || null;
}
